package com.ferris.androidpattern;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.ferris.composite.Animal;
import com.ferris.composite.House;
import com.ferris.composite.PersonAnimal;
import com.ferris.composite.PigAnimal;
import com.ferris.ioc.ClickMethod;
import com.ferris.ioc.InjectView;
import com.ferris.ioc.UIBindUtil;
import com.ferris.observice.Student;
import com.ferris.observice.Teacher;

public class MainActivity extends FragmentActivity {
	private House house;

	@InjectView(id = R.id.button1, clickMethod = "onClickCallback")
	private Button Button1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		UIBindUtil.bind(this);

		 house=House.getHouseInstance();//得到一个房间

		 //人进入房间了
		 PersonAnimal json=new PersonAnimal();
		 json.setId(1);
		 json.setName("我是人");
		 json.setType(Animal.Attribute.PEOPLE);
		 house.addAnimal(json);//一个人进入房间了


		 PigAnimal pig=new PigAnimal();
		 pig.setId(2);
		 pig.setName("我是猪");
		 pig.setType(Animal.Attribute.PIG);
		 house.addAnimal(pig);//猪也进入房间了

		 Toast.makeText(MainActivity.this, "房间里有多少动物："+house.getAnimalCount(),
		 Toast.LENGTH_LONG).show();

		 Teacher teacher=new Teacher(); //被观察者
		 Student student=new Student();
		 student.setContext(this);
		 student.setGirl(teacher);//添加观察对象


		 teacher.setString("大家好我是老师哦！");

	}

	@ClickMethod(R.id.button1)
	public void onClickCallback(View view) {
		Toast.makeText(MainActivity.this, "我是注解", Toast.LENGTH_LONG).show();
	}

}
